<?php
include 'class/user.php';
//include 'class/toko.php';
//include 'config/koneksi.php';

if(isset($_POST["Login"])){
	if($_POST["email"]=="" || $_POST["password"]=="" ){
		echo "<script>alert('Silahkan isikan Email dan Password terlebih dahulu!');</script>";}
		else {
				$user = new User();
				$user->email=$_POST['email'];
				$user->password=$_POST['password'];
				$User_Dao=new User_Dao();
				if(!$User_Dao->cek_user($user)){
					echo"<script>alert('Email dan Password tidak sesuai!');</script>";
				}
				if($User_Dao->cek_user($user)){
					$nama=$User_Dao->get_email($user->email);   //menyimpan array user berdasarkan parameter email
					if($nama->level=="admin"){
						session_start();
						$_SESSION['Username'] = "admin";
						$_SESSION['Id'] = $nama->id;
						header ("Location:backend/masteradmin.php");
					}
				
					if($nama->level=="toko"){
						$Toko_Dao=new Toko_Dao();
						$toko=$Toko_Dao->get($nama->id);
						session_start();
						$_SESSION['Username'] = $toko->nama_toko;
						$_SESSION['Id'] = $toko->id_toko;
						$_SESSION['Email'] = $email;
						header ("Location:toko/masteradmin.php");
					}
				} 
				
	}
}	
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script type="text/javascript" src="../js/jquery.tools.min.js"></script>
<style type="text/css">
</style>

    <script type="text/javascript"> 
      $(document).ready(function(){
        	$("#kotak").click(function() {
        		$(this).expose({api: true}).load();
	        });
	    });
	  </script>
	
    <style>
      #kotak {
	       border:1px solid #000;
	       background-color:#fff;
	       padding:50px;
	       font-size:20px;
	       margin:20px auto;
	       text-align:center;
	       width:400px;
		}
  </style>
  </head>
      <body>
      <div id="kotak">
<table align=center width=355>
<tr>
<td>
<h2><font face=tahoma>Login Toko dan Admin</font></h2>
<img src="../wos/images/login-welcome.gif" width="100" height="100" hspace="10" align="left"></img>
<form id="login" name="form" method="post" >
<table>
<tr><td><font face=tahoma size=2>Email</font></td><td> <font face=tahoma size=2>:</font> <input type="text" name="email" value=""></td></tr>
<tr><td><font face=tahoma size=2>Password</font></td><td> <font face=tahoma size=2>:</font> <input type="password" name="password" value=""></td></tr>
<tr><td><input type="submit" name="submit" value="Submit" id="Submit"></td></tr>
</table>
<input type="hidden" name="Login" value="login">
</form>
</td>
</tr>
<tr>
<td>

			<div align=center><font face=tahoma size=2>
			Toko Anda Belum Tedaftar Sebagai Member ? Silahkan Klik <a href='?menu=registrasi'>Disini</a><br><br>

WOS.com</font></div></td></tr></table>
      </div>
  </body>
</html>



